<template>
  <div>
    <el-form style="overflow: auto" :inline="true" @submit.native.prevent>
      <el-form-item>
        <el-select @change="statusChange" style="width: 120px" v-model="typeInfo.status" placeholder="请选择">
          <el-option label="全部" value=""> </el-option>
          <el-option :label="'已审批'" value="1"> </el-option>
          <el-option :label="'未审批'" value="0"> </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-input v-model="typeInfo.title" @keyup.enter="search()" placeholder="请输入项目名称"
          style="width: 20em; margin-right: 15px" clearable />
      </el-form-item>
      <el-form-item>
        <el-button type="default" @click="search()">搜索</el-button>
      </el-form-item>
    </el-form>
    <!--   v-infinite-scroll="load" 无限滚动 -->
    <el-table :infinite-scroll-disabled="disabled" stripe border :data="resultList" style="width: 100%"
      row-key="menuId">
      <el-table-column label="序号" type="index" width="70" center></el-table-column>
      <el-table-column label="用户名" prop="nickName"></el-table-column>
      <el-table-column label="工号" prop="userName"></el-table-column>
      <el-table-column label="专业" prop="major"></el-table-column>
      <!-- <el-table-column label="上传文件数量" prop="evidenceCount"></el-table-column> -->
      <!-- <el-table-column  label="审批结果" prop="score"></el-table-column> -->
      <el-table-column label="状态" prop="status"></el-table-column>
      <el-table-column label="审批">
        <template slot-scope="scope">
          <el-button v-if="scope.row.status == '0'" @click="toExamine(scope)" type="text">审批
          </el-button>
          <div v-else style="color: #999">已完成审批！</div>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :page-sizes="[10, 20, 50, 100]"
      :current-page.sync="current" :page-size="size" layout="sizes, prev, pager, slot" :total="total" row-key>
      <el-button type="text" @click="showMore" v-show="size > 0">下一页</el-button>
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: "examine",
  data() {
    return {
      resultList: [],
      typeInfo: {
        title: "",
        status: "",
        page: 1,
        limit: 10,
        pId: this.$route.query.pId,
      },
      size: 10,
      current: 1,
      total: 0,
    };
  },
  methods: {
    async handleSizeChange(val) {
      this.size = val;
      this.resultList = [];
      this.typeInfo.page = this.current;
      this.typeInfo.limit = this.size;
      let result = await this.$get("/api/project/result", this.typeInfo);
      // if(result.code!=200) return this.$message.error(result.msg)
      result.data.list.map((item) => {
        item.status = item.status ? "已审批" : "未审批";
      });
      this.resultList.push(...result.data.list);
      console.log(this.resultList);
      this.total = result.data.total;
    },
    async handleCurrentChange(val) {
      this.current = val;
      console.log(this.current);
      this.resultList = [];
      this.typeInfo.page = this.current;
      this.typeInfo.limit = this.size;
      let result = await this.$get("/api/project/result", this.typeInfo);
      // if(result.code!=200) return this.$message.error(result.msg)
      result.data.list.map((item) => {
        item.status = item.status ? "已审批" : "未审批";
      });
      this.resultList.push(...result.data.list);
      console.log(this.resultList);
      this.total = result.data.total;
    },
    async showMore() {
      if (this.current < this.total / this.size) {
        this.current++;
        this.resultList = [];
        this.typeInfo.page = this.current;
        this.typeInfo.limit = this.size;
        let result = await this.$get("/api/project/result", this.typeInfo);
        // if(result.code!=200) return this.$message.error(result.msg)
        result.data.list.map((item) => {
          item.status = item.status ? "已审批" : "未审批";
        });
        this.resultList.push(...result.data.list);
        console.log(this.resultList);
        this.total = result.data.total;
      } else {
        this.$message({
          message: "已经是最后一页",
          type: "warning",
        });
      }
    },
    async initResultList() {
      let result = await this.$get("/api/project/result", this.typeInfo);
      // if(result.code!=200) return this.$message.error(result.msg)
      // result.data.list.map((item) => {
      //   item.status = item.status ? "已审批" : "未审批";
      // });
      this.resultList.push(...result.data.list);
      console.log(this.resultList);
      this.total = result.data.total;
    },
    // load() {
    //   this.typeInfo.page++;
    //   this.initResultList();
    // },
    resetInfo() {
      this.resultList = [];
      this.typeInfo.page = 1;
    },
    search() {
      this.resetInfo();
      this.initResultList();
    },
    // 切换项目状态回调
    statusChange(val) {
      this.resetInfo();
      this.typeInfo.status = val;
      this.initResultList();
    },
    toExamine(scope) {
      // this.$store.commit('removeAnalogueTab',"/home/examineDetails")
      this.$router.push(
        "/home/examineDetails?pId=" +
        this.$route.query.pId +
        "&uId=" +
        scope.row.userId
      );
    },
    // rePulse(id){
    //   this.$confirm('确定将该用户结果打回？','提示',{
    //     confirmButtonText: '确定',
    //     cancelButtonText: '取消',
    //     type: 'warning'
    //   }).then(()=>{
    //     let result=this.$post('/api/submit/approve',{parentId:id,pId:this.$route.query.id,isFlag:1})
    //     if(result.code==200) {
    //       this.resetInfo()
    //       this.initResultList()
    //       this.$message.success(result.msg)
    //     }
    //   })
    // }
  },
  mounted() {
    this.initResultList();
  },
  computed: {
    disabled() {
      return this.resultList.length != this.total;
    },
  },
};
</script>

<style></style>
